/*
 ============================================================================
 Name		: CStreamAudioEngine.h
 Author	  : 
 Version	 : 1.0
 Copyright   : copyright readever.cn
 2009-2010
 Description : CStreamAudioEngine declaration
 ============================================================================
 */

#ifndef CSTREAMAUDIOENGINE_H
#define CSTREAMAUDIOENGINE_H

#if !defined(__MDA_COMMON_AUDIO_H__)
#include <mda\common\audio.h>
#endif

#if !defined(__MDA_CLIENT_UTILITY_H__)
#include <Mda\Client\Utility.h>
#endif

#if !defined(__MDA_COMMON_RESOURCE_H__)
#include <Mda\Common\Resource.h>
#endif

#if !defined(__MDAAUDIOOUTPUTSTREAM_H__)
#include <MdaAudioOutputStream.h>
#endif


const TInt KVolSliderLength = 10;

const TInt KInitialVolume = 9;

const TInt KNumBuf = 2;
const TInt KBufferSize = 5000;

class CEikonEnv;
class CMP3DecodeEngine;

// INCLUDES
#include <e32std.h>
#include <e32base.h>

// CLASS DECLARATION

/**
 *  CStreamAudioEngine
 * 
 */
class CStreamAudioEngine : public CBase, public MMdaAudioOutputStreamCallback
	{
public:
	// Constructors and destructor
    enum TEngineStatus
        {
        EEngineNotReady,
        EEngineReady,
        EEngineToPause,
        EEnginePause,
        EEnginePlaying        
        };
	/**
	 * Destructor.
	 */
	~CStreamAudioEngine();

	/**
	 * Two-phased constructor.
	 */
	static CStreamAudioEngine* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CStreamAudioEngine* NewLC();

	 void PlayL();
	 void Pause();
	 void StopL();
	 void SetRepeat(TBool aRepeat);
	 void OpenL(TFileName  aFileName, int mediaoffset = 0, int mediarealsize = 0);
	 
	 //inline functions
	 inline TInt Volume();
	 inline TBool StreamReady(); 
	 inline TBool StreamPlaying();
	 inline TBool StreamPause();
	 inline TBool StreamRepeat();
	 void SetVolume(TInt aVol);
	 
public://from mmdaaudiooutputstreamcallback
	virtual void MaoscOpenComplete(TInt aError);
	virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer);
	virtual void MaoscPlayComplete(TInt aError);
	
protected:
    // displays error messages
    void ShowErrorMsg(TInt aResourceBuf, TInt aError);
    
private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CStreamAudioEngine();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();
	void NextBuffer(const TDesC8& aBuffer);

private:
	
	TInt iVolume;               // volume
	TInt iVolStep;      
	TBool iFileOK;              // indicates if file has been successfully read to buffer 
	TEngineStatus iMp3Status;      // engine status
	TBool iPlayFile;            // which buffer is currently in use

	TBool iRepeat;

	TUint16* aa; 
	 
	TPtr imp3Buf; 

	TBool iStart;

	TBuf8<KBufferSize> iBufList[KNumBuf];

	CMdaAudioOutputStream* iStream;
	//CMdaAudioOutputStream* iStream1;
	TMdaAudioDataSettings iSettings;


	CEikonEnv* iEnv;

	CMP3DecodeEngine * imp3;
	RFs fss;
	TFileName tFullFileName;
	TInt  fm;

	TInt  bufx;
	//william
	int iMediaRealSize;
	int iMediaOffset;


	};

#endif // CSTREAMAUDIOENGINE_H
